<?php
/**
 * 报名管理
 * @author Administrator
 */
class baoming extends admin{
    public function __construct(){
        parent::__construct();
    }
    public function pt_color(){
        $mark = intval($_POST['mark']);
        $rs_color=db()->getAll('select id,real_name,mobile,school_name,taocan_name,taocan_price,yhq_price,has_pay,status,create_time,sex,mark,remark from x_baoming WHERE  school_id = "' . $_SESSION['client']['jx_id'] . '"  and  mark="'.$mark.'" order by id DESC ');
        foreach ($rs_color as $k=>$v){
            $rs_color[$k]['create_time'] = date('Y-m-d',$v['create_time']);
            $rs_color[$k]['sex'] = $v['sex'];
            if( $v['sex']=="-1") $rs_color[$k]['sex'] = '未知';
            if( $v['sex']=="0") $rs_color[$k]['sex'] = '女';
            if( $v['sex']=="1") $rs_color[$k]['sex'] = '男';
            if( $v['status']=="-1") $rs_color[$k]['status'] = '取消报名';
            if( $v['status']=="0") $rs_color[$k]['status'] = '未付款';
            if( $v['status']=="1") $rs_color[$k]['status'] = '已交报名费';
            if( $v['status']=="2") $rs_color[$k]['status'] = '科目二费用';
            if( $v['status']=="3") $rs_color[$k]['status'] = '科目三';
            if( $v['status']=="100") $rs_color[$k]['status'] = '完全支付';
        }
        if($rs_color) $return=array('status'=>1,'info'=>$rs_color);
        else $return = array('status'=>0,'info'=>'系统繁忙,请稍后重试');
        echo json_encode($return);
    }
    public function pt_remark(){
        if($_POST['bool']==1){
            $id = intval($_POST['id']);
            $rs = db()->getRow("select id,remark from x_baoming WHERE id=".$id);
            if($rs) $return = array('status'=>1,'info'=>$rs);
            else $return=array('status'=>0,'info'=>'系统繁忙,请稍后重试');
            echo json_encode($return);
        }else{
        $id = intval($_POST['id']);
        $date['remark'] = trim($_POST['textarea']);
        $rs= db()->update('x_baoming',$date,'id='.$id);
        insertlogs('update','修改车辆信息(ID:'.$id.')',$date,$id);
        if($rs !==false)$return = array('status'=>1,'info'=>$date);
        else $return = array('status'=>0,'info'=>'标志修改失败');
        echo json_encode($return);
        }
    }
    public function tabs(){
       $id = intval($_POST['id']);
       $mark = intval($_POST['mark']);
       if($mark==0) $date['mark'] =1;
       else $date['mark'] =0;
        $rs = db()->update('x_baoming',$date,'id='.$id);
        if($rs !==false) $return = array('status'=>1,'info'=>$date);
        else $return = array('status'=>0,'info'=>'标志修改失败');
        echo json_encode($return);
    }
    public function select(){
        $where = ' where 1=1 and school_id = "' . $_SESSION['client']['jx_id'] . '"';
        $type = is_numeric($_GET['str_search']);
        if( $type == 1){
            $where .= ' and mobile ="'.$_GET['str_search'].'"';
        }
        if($_GET['str_search']!=''&&$type!= 1){
            $where .= ' and real_name ="'.$_GET['str_search'].'"';
        }
         $total=db()->getOne('select count(*) from x_baoming'.$where);
        // //$pagesize=C('PAGE_SIZE');
         $pagesize=8;
         if (isset($_GET['p']) && (int) $_GET['p'] > 0) $p = (int) $_GET['p'];
         else $p = 1;
         $limit=' limit '.($p-1)*$pagesize.','.$pagesize;
        $sql = 'select id,real_name,mobile,school_name,taocan_name,taocan_price,yhq_price,has_pay,status,create_time,sex,mark,remark from x_baoming '.$where.' order by id DESC '.$limit;
        $list=db()->getAll($sql);
        if(!$list) $list=array();
        foreach ($list as $k=>$v){
            $list[$k]['create_time'] = date('Y-m-d',$v['create_time']);
            $list[$k]['sex'] = $v['sex'];
            if( $v['sex']=="-1") $list[$k]['sex'] = '未知';
            if( $v['sex']=="0") $list[$k]['sex'] = '女';
            if( $v['sex']=="1") $list[$k]['sex'] = '男';
            if( $v['status']=="-1") $list[$k]['status'] = '取消报名';
            if( $v['status']=="0") $list[$k]['status'] = '未付款';
            if( $v['status']=="1") $list[$k]['status'] = '已交报名费';
            if( $v['status']=="2") $list[$k]['status'] = '科目二费用';
            if( $v['status']=="3") $list[$k]['status'] = '科目三';
            if( $v['status']=="100") $list[$k]['status'] = '完全支付';
        }
        $page = array('total' => $total,'pagesize' =>$pagesize,'curpage' => $p);
        echo json_encode(array('status'=>1,'info'=>$list,'page'=>$page));
    }
  
    public function index(){
        if(IS_AJAX){
            $start = isset($_GET['price_min'])&&!empty($_GET['price_min'])?strtotime($_GET['price_min']):0;
            $end = isset($_GET['price_max'])&&!empty($_GET['price_max'])?strtotime($_GET['price_max']):NOW;
            $where ='where create_time between '.$start.' and '.$end;
            
            if(isset($_GET['bm_id'])&&$_GET['bm_id']!='') $where.=' and id="'.(int)($_GET['bm_id']).'"';
             
            if(isset($_GET['mobile'])&&$_GET['mobile']!='') $where.=' and mobile="'.trim($_GET['mobile']).'"';
            if(isset($_GET['pay_type'])&&(int)$_GET['pay_type']>0) $where.=' and pay_type='.(int)$_GET['pay_type'];
            if(isset($_GET['status'])&&is_numeric($_GET['status'])) $where.=' and status='.(int)$_GET['status'];
            if(isset($_GET['taocan_id'])&&(int)$_GET['taocan_id']>0) $where.=' and taocan_id='.(int)$_GET['taocan_id'];
            
            $total=db()->getOne('select count(*) from x_baoming '.$where);
            $pagesize=C('PAGE_SIZE');
            if (isset($_GET['p']) && (int) $_GET['p'] > 0) $p = (int) $_GET['p'];
            else $p = 1;
            $limit=' limit '.($p-1)*$pagesize.','.$pagesize;
            $sql = 'select id,real_name,mobile,school_name,taocan_name,taocan_price,yhq_price,has_pay,status,create_time from x_baoming '.$where.' order by id DESC '.$limit;
            $list=db()->getAll($sql);
            if(!$list) $list=array();
            $page = array('total' => $total,'pagesize' =>$pagesize,'curpage' => $p);
            $this->ajaxReturn(array('status'=>1,'data'=>$list,'page'=>$page));
        }else{
            $tpl=$this->Template();
            $tpl->display();
        }
    }
    
    //线下报名第一步
    public function step(){
        $tpl=$this->Template();
        $tpl->display();
    }
    
    //线下支付——添加
    public function add(){
        if (IS_AJAX){
            $bm_id=(int)$_GET['bm_id'];
            $uid = db()->getOne('select uid from x_baoming where id='.$bm_id);
            
            $data['uid'] = $uid;
            $data['bm_id'] = $bm_id;
            $data['order_no']=date('ymdHis').mt_rand(100,999).substr($uid,-1);//生成订单号
            $data['title'] = $_POST['title'];
            $data['amount'] = $_POST['amount'];
            $data['create_time'] = NOW;
            $data['pay_time'] = strtotime($_POST['pay_time']);
            $data['pay_type'] = 3;  //3：线下支付
            $data['status'] = 1;    //线下已付
            $data['remark'] = trim($_POST['remark']);
            $data['pay_label'] = $_POST['pay_label'];
            
            $insert_id=db()->insert('x_order',$data);
            if($insert_id){
                $this->ajaxReturn(array('status'=>'y','info'=>'添加成功'));
            }else{
                $this->ajaxReturn(array('status'=>'n','info'=>'添加失败'));
            }
        }else {
            $bm_id=(int)$_GET['bm_id'];
            $taocan_id = db()->getOne('select taocan_id from x_baoming where id='.$bm_id);
            $tpl=$this->Template();
            $tpl->assign('taocan_id',$taocan_id);
            $tpl->display();
        }

        
    }

    

    
}